<?php
/**
 * 任务接取列表
 * author itholiday@126.com
 */
global $_W, $_GPC;
load()->func('tpl');
$html_title = $_W['current_module']['title'];
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'list';
//页面显示条数
$pagesize = 15;
$page = max(1, $_GPC['page']);
$start = ($page - 1) * $pagesize;

$where = 'A.id>0 ';

$userinfo = isset($_GPC['userinfo']) && !empty($_GPC['userinfo']) ? input('userinfo') : '';
$title = isset($_GPC['title']) && !empty($_GPC['title']) ? input('title') : '';
$start_time = isset($_GPC['start_time']) && !empty($_GPC['start_time']) ? strtotime($_GPC['start_time']) : '';
$end_time = isset($_GPC['end_time']) && !empty($_GPC['end_time']) ? strtotime($_GPC['end_time']) : '';
$receive_status = isset($_GPC['receive_status']) && $_GPC['receive_status'] != '' ? $_GPC['receive_status'] : '';
$review_status = isset($_GPC['review_status']) && $_GPC['review_status'] != '' ? $_GPC['review_status'] : '';

if (!empty($userinfo)) {
    $where .= " and (B.mobile like '%$userinfo%' or B.truename like '%$userinfo%') ";
}

if (!empty($title)) {
    $where .= " and C.title like '%$title%' ";
}

if ($receive_status != '') {
    $where .= " and A.receive_status=$receive_status ";
}

if ($review_status != '') {
    $where .= " and A.review_status=$review_status ";
}

if (!empty($start_time) && !empty($end_time)) {
    $where .= " and A.receive_time>=$start_time and A.receive_time<=$end_time ";
} else {
    if (!empty($start_time)) {
        $where .= " and A.receive_time>=$start_time ";
    }
    if (!empty($end_time)) {
        $where .= " and A.receive_time<=$end_time ";
    }
}

if ($op == 'list' || $op == '') {

    $total = pdo_fetchcolumn('SELECT COUNT(*) AS `number` FROM ' . tablename('yq_haircircle_task_receive') . ' A left join ims_yq_haircircle_users B on A.user_id=B.id left join ims_yq_haircircle_task C on A.taskid=C.id WHERE ' . $where);

    //生成分页HTML
    $pager = getPageHTML($total, $page, $pagesize);
    $sql = "select A.*,B.mobile,C.title,C.task_money from ims_yq_haircircle_task_receive A left join ims_yq_haircircle_users B on A.user_id=B.id left join ims_yq_haircircle_task C on A.taskid=C.id where $where order by A.id desc limit $start,$pagesize";
    $list = pdo_fetchall($sql);
    include $this->template('web/task_receive_list');
    exit;
}